package com.zlm.tcp;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author: 郑
 *
 */
public class TcpUpServer {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9632);
        //监听客户端连接，阻塞式监听
        Socket socket = serverSocket.accept();
        //获取输入流
        InputStream is = socket.getInputStream();
        //文件读取写入
        FileOutputStream fos = new FileOutputStream(new File("aaa.jpg"));
        byte[] buffer = new byte[1024];
        int len;
        while ((len = is.read(buffer)) != -1) {
            fos.write(buffer,0,len);
            fos.flush();
        }
        //给出反馈
        OutputStream os = socket.getOutputStream();
        os.write("图片上传成功".getBytes());
        os.flush();
        os.close();
        fos.close();
        is.close();
        socket.close();
        serverSocket.close();

    }
}
